﻿using Core.Database.Model;
using Core.Info;
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using CDM = Core.Database.Model ;
namespace Entity.Core.Database
{
    /// <summary>
    /// 数据库配置模型
    /// </summary>
    public class DatabaseConfigEntity:BaseEntity
    {
        /// <summary>
        /// 唯一Id
        /// </summary>
        [JsonProperty("guid")]
        public virtual string? Guid { get; set; }

        /// <summary>
        /// 连接组名称，为空默认赋值-guid，用于读写分离连接同组划分
        /// </summary>
        [JsonProperty("connection_group")]
        public virtual string? ConnectionGroup { get; set; }

        /// <summary>
        /// 从库标识
        /// </summary>
        [JsonProperty("slave_flag")]
        public virtual bool SlaveFlag{ get; set; }

        /// <summary>
        /// 连接名称
        /// </summary>
        [JsonProperty("connection_name")]
        public virtual string? ConnectionName { get; set; }

        /// <summary>
        /// 数据库类型
        /// </summary>
        [JsonProperty("database_type")]
        [JsonConverter(typeof(StringEnumConverter))]
        public virtual DatabaseType? DatabaseType { get; set; }

        /// <summary>
        /// 排序号
        /// </summary>
        [JsonProperty("sort_number")]
        public virtual int SortNumber { get; set; } = 1;

        /// <summary>
        /// 数据库名称
        /// </summary>
        [JsonProperty("database_name")]
        public virtual string? DatabaseName { get; set; }

        /// <summary>
        /// 数据库地址
        /// </summary>
        [JsonProperty("address")]
        public virtual string? Address { get; set; }

        /// <summary>
        /// 数据库端口
        /// </summary>
        [JsonProperty("port")]
        public virtual string? Port { get; set; }

        /// <summary>
        /// 针对此特定连接字符串连接池中所允许的最大连接数，如果未提供任何值，则为 100
        /// </summary>
        [JsonProperty("max_pool_size")]
        public virtual uint? MaxPoolSize { get; set; } = 100;

        /// <summary>
        /// 数据库用户
        /// </summary>
        [JsonProperty("user_name")]
        public virtual string? UserName { get; set; }

        /// <summary>
        /// 数据库密码
        /// </summary>
        [JsonProperty("password")]
        public virtual string? Password { get; set; }


        /// <summary>
        /// 超时时间
        /// </summary>
        [JsonProperty("timeout")]
        public virtual uint Timeout { get; set; } = 60 * 60;

        /// <summary>
        /// 本地sqlite配置
        /// </summary>
        public static DatabaseConfigEntity LocalSqlite { get; } = new DatabaseConfigEntity()
        {
            Address = Path.Combine(AppInfo.LocalStorageDirectory,"local.db"),
            ConnectionName = "local",
            DatabaseName = "local",
            DatabaseType = CDM.DatabaseType.Sqlite,
            ConnectionGroup = "local",                       
        };
    }
}
